﻿// 内存缓存
const cache: Record<string, string> = {};

/**
 * 从本地存储获取数据（带内存缓存）
 */
export function getCache(key: string): string | null {
  if (cache[key] !== undefined) return cache[key];

  const data = cc.sys.localStorage.getItem(key);
  if (
    data == null ||
    data === "null" ||
    data === "undefined" ||
    data === "" ||
    data === "NaN"
  ) {
    return null;
  }

  cache[key] = data;
  return data;
}

/**
 * 存储数据到本地（同步内存缓存）
 */
export function setCache(key: string, value: string): void {
  cache[key] = value;
  cc.sys.localStorage.setItem(key, value);
}
